#include <Adafruit_NeoPixel.h>

class RGB
{
    Adafruit_NeoPixel strip;
    unsigned long flashRGBTimer = 0;

public:
    RGB(uint16_t n, int16_t pin, neoPixelType type = NEO_GRB + NEO_KHZ800) : strip(n, pin, type)
    {
    }

    Adafruit_NeoPixel &getStrip()
    {
        return strip;
    }
    // 设置亮度（0-255范围）
    void begin(uint8_t light)
    {
        strip.begin();
        strip.setBrightness(light);
    }

    void loop(bool bFlash,unsigned long delay,uint8_t r=0,uint8_t g=0,uint8_t b=0)
    {
        if (bFlash && (millis() - flashRGBTimer > delay))
        {
            static bool RGBON=false;
            showRGB(RGBON=!RGBON, r, g, b);
            flashRGBTimer = millis();
        }
    }

    void showRGB(bool bShow, uint8_t r = 0, uint8_t g = 0, uint8_t b = 0)
    {
        if (bShow)
        {
            strip.setPixelColor(0, strip.Color(r, g, b)); // 设置灯珠 (R, G, B)
        }
        else
        {
            strip.clear();
        }
        strip.show(); // 显示颜色
    }

    void flashRGB(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0)
    {
        showRGB(true, r, g, b);
        delay(10);
        showRGB(false);
    }
};